import React, { Component } from 'react';
import FileUpload from './react-fileupload.jsx';

class FileUploader extends Component {
	render() {
		const options = {
			baseUrl: '/api/manage/product/upload.do',
			fileFielName: 'upload_file',
			dataType: 'json',
			chooseAndUpload: true,
			uploadSuccess: res => {this.props.onSuccess(res.data)},
			uploadError: error => {this.props.onError(error.message || '上传图片出错了')},
		}
		return (
			<FileUpload options={options}>
				<button ref="chooseAndUpload" className="btn btn-xs btn-default">选择图片</button>
			</FileUpload>
		);
	}
}

export default FileUploader;
